﻿using System;
using ASPNETVN.PORTAL.Components.Helpers;
using ASPNETVN.PORTAL.Components.Configuration.Settings;
using ASPNETVN.PORTAL.Components.UI;
using ASPNETVN.PORTAL.Components.UI.DataTypes;

namespace ASPNETVN.PORTAL.Modules.PhotoAlbum
{
    public enum ModulePages
    {
        Collection,
        CollectionDetail,
        ImageSlideshow
    }

    public partial class Main : PortalModuleControl
    {
        public Main()
        {
            ModuleSettingItem uploadPath = new ModuleSettingItem(new StringDataType("Uploads"));
            uploadPath.Name = "Thư mục upload";
            uploadPath.Description = "Thư mục upload";
            uploadPath.Order = 0;
            this.BaseSettings.Add("UploadPath", uploadPath);
        }

        //-----------------------------------------------------------------------------------------
        private void loadChildControl()
        {
            const string basePath = "~/Modules/PhotoAlbum/";
            const string pageQuery = "page";
            string pageName = Request.QueryString[pageQuery];

            ModulePages page;
            if (pageName == null)
            {
                page = ModulePages.Collection;
            }
            else
            {
                page = (ModulePages)Enum.Parse(typeof(ModulePages), Request.QueryString[pageQuery], true);
            }

            string src = string.Format("{0}Controls/{1}.ascx", basePath, page);
            ModulePage ctl = (ModulePage)this.LoadControl(src);
            ctl.ParentControl = this;
            this.Controls.Add(ctl);
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            this.loadChildControl();
            this.ModuleTitle.AddUrl = HttpUrlBuilder.BuildAddEditUrl(this.ModuleID, 0, "page=AddEditCollection");
        }
    }
}